﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;

namespace DAL
{
    public class CHUCVUDAO:DALBase
    {
        public CHUCVUDAO()
        {
            this.OpenConnect();
        }

        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPCHUCVU"; }
            set { _SpName = value; }
        }

        public List<CHUCVU> GetListCV()
        {
            List<CHUCVU> cv = new List<CHUCVU>();
            dt = new DataTable();

			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new CHUCVU(), null), ConvertClassToArray.GetValues(new CHUCVU(), 0));
				cv = (List<CHUCVU>)ConvertDatatableToList.ConvertTo<CHUCVU>(dt);
			}

			catch { return null; }

            return cv;
        }
		public DataTable GetListCVs()
		{
			dt = new DataTable();

			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new CHUCVU(), null), ConvertClassToArray.GetValues(new CHUCVU(), 0));

			}

			catch { return null; }

			return dt;
		}


        public String CreateNewID()
        {

            try
            {
                return "CV" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new CHUCVU(), null), ConvertClassToArray.GetValues(new CHUCVU(), 4));

            }
			catch { return null; }
        }
        public bool INSERT(CHUCVU cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 1)) == 1);

            }
			catch { return false; }
        }
        public bool UPDATE(CHUCVU cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

            }
			catch { return false; }
        }
        public bool DELETE(CHUCVU cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

            }
			catch { return false; }
        }
    }
}